package com.aiyige.base.eventbus;

import android.os.Parcel;
import android.os.Parcelable;

import com.aiyige.page.publish.selectcourse.model.Course;
import com.aiyige.page.publish.selecttraingcard.model.TraingCard;

import java.util.LinkedList;
import java.util.List;

/**
 * Created by zhuyakun on 2017/12/6.
 */

public class EventSelectCourse implements Parcelable {
    public static final int RESULT_OK = 1;
    public static final int RESULT_CANCEL = 2;
    int resultCode;
    List<Course> courseList;

    public EventSelectCourse() {
    }

    private EventSelectCourse(Builder builder) {
        setResultCode(builder.resultCode);
        setCourseList(builder.courseList);
    }

    public static Builder newBuilder() {
        return new Builder();
    }

    public int getResultCode() {
        return resultCode;
    }

    public void setResultCode(int resultCode) {
        this.resultCode = resultCode;
    }

    public List<Course> getCourseList() {
        return courseList;
    }

    public void setCourseList(List<Course> courseList) {
        this.courseList = courseList;
    }

    public static final class Builder {
        private int resultCode;
        private List<Course> courseList;

        private Builder() {
            resultCode = RESULT_CANCEL;
            courseList = new LinkedList<>();
        }

        public Builder resultCode(int resultCode) {
            this.resultCode = resultCode;
            return this;
        }

        public Builder courseList(List<Course> courseList) {
            this.courseList = courseList;
            return this;
        }

        public EventSelectCourse build() {
            return new EventSelectCourse(this);
        }
    }

    @Override
    public int describeContents() {
        return 0;
    }

    @Override
    public void writeToParcel(Parcel dest, int flags) {
        dest.writeInt(this.resultCode);
        dest.writeTypedList(this.courseList);
    }

    protected EventSelectCourse(Parcel in) {
        this.resultCode = in.readInt();
        this.courseList = in.createTypedArrayList(Course.CREATOR);
    }

    public static final Creator<EventSelectCourse> CREATOR = new Creator<EventSelectCourse>() {
        @Override
        public EventSelectCourse createFromParcel(Parcel source) {
            return new EventSelectCourse(source);
        }

        @Override
        public EventSelectCourse[] newArray(int size) {
            return new EventSelectCourse[size];
        }
    };
}
